from multiprocessing.spawn import old_main_modules
from time import sleep

from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By

from Common.Utils import BlogDriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Center:
    url = ""
    driver = ""


    def __init__(self):
        self.url = "http://127.0.0.1:58080/index.html"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)

    def Revise(self):
        sleep(2)
        #进入个人中心
        self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        self.driver.find_element(By.CSS_SELECTOR, "#index_user_settings").click()
        sleep(1)
        # #修改昵称
        BlogDriver.getScreenshort()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_nickname").send_keys("小明")
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_nickname").click()
        new_nickname=self.driver.find_element(By.CSS_SELECTOR, "#setting_input_nickname").text
        assert new_nickname=="小明"
        sleep(1)
        BlogDriver.getScreenshort()

        self.driver.refresh()
        sleep(1)
        BlogDriver.getScreenshort()
        #修改、填写邮箱
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_email").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_email").send_keys("123@qq.com")
        sleep(1)
        BlogDriver.getScreenshort()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_email").click()
        sleep(1)
        BlogDriver.getScreenshort()

        #修改、填写电话号码
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_phoneNum").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_phoneNum").send_keys("12345678910")
        sleep(1)
        BlogDriver.getScreenshort()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_phoneNum").click()
        sleep(1)
        BlogDriver.getScreenshort()
        #修改个人简介

        text=self.driver.find_element(By.CSS_SELECTOR,"#settings_textarea_remark")
        text.clear()
        self.driver.execute_script("arguments[0].scrollIntoView(true);", text)
        sleep(2)
        text.send_keys("你们好，我是叫小明！")

        BlogDriver.getScreenshort()
        self.driver.find_element(By.CSS_SELECTOR,"#settings_submit_remark").click()
        sleep(1)
        BlogDriver.getScreenshort()

        #修改密码
        #错误原密码，相同确认密码
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_oldPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").clear()

        oldpass=self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").text
        self.driver.execute_script("arguments[0].type='text';", oldpass)
        newpass = self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").text
        self.driver.execute_script("arguments[0].type='text';", newpass)
        repeatpass = self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").text
        self.driver.execute_script("arguments[0].type='text';", repeatpass)

        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("654321")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("123456")

        submit_button=WebDriverWait(self.driver,10).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR,"#settings_submit_password"))
        )
        self.driver.execute_script("arguments[0].scrollIntoView(true);",submit_button)
        sleep(4)
        BlogDriver.getScreenshort()
        submit_button.click()
        sleep(1)
        BlogDriver.getScreenshort()

        #错误原密码，不同确认密码
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_oldPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").clear()

        oldpass=self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").text
        self.driver.execute_script("arguments[0].type='text';", oldpass)
        newpass = self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").text
        self.driver.execute_script("arguments[0].type='text';", newpass)
        repeatpass = self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").text
        self.driver.execute_script("arguments[0].type='text';", repeatpass)

        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("654321")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("654321")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("123456")

        submit_button=WebDriverWait(self.driver,10).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR,"#settings_submit_password"))
        )
        self.driver.execute_script("arguments[0].scrollIntoView(true);",submit_button)
        sleep(4)
        BlogDriver.getScreenshort()
        submit_button.click()
        sleep(1)
        BlogDriver.getScreenshort()

        #新密码和确认密码为原密码
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").clear()

        oldpass = self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").text
        self.driver.execute_script("arguments[0].type='text';", oldpass)
        newpass = self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").text
        self.driver.execute_script("arguments[0].type='text';", newpass)
        repeatpass = self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").text
        self.driver.execute_script("arguments[0].type='text';", repeatpass)

        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("123456")

        submit_button = WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR, "#settings_submit_password"))
        )
        self.driver.execute_script("arguments[0].scrollIntoView(true);", submit_button)
        sleep(4)
        BlogDriver.getScreenshort()
        submit_button.click()
        sleep(1)
        BlogDriver.getScreenshort()


        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("小ming")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        sleep(1)
        BlogDriver.getScreenshort()

        # 正确原密码，正确新密码和确认新密码
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").clear()

        oldpass = self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").text
        self.driver.execute_script("arguments[0].type='text';", oldpass)
        newpass = self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").text
        self.driver.execute_script("arguments[0].type='text';", newpass)
        repeatpass = self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").text
        self.driver.execute_script("arguments[0].type='text';", repeatpass)

        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("1234567")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("1234567")

        submit_button = WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR, "#settings_submit_password"))
        )
        self.driver.execute_script("arguments[0].scrollIntoView(true);", submit_button)
        sleep(4)
        BlogDriver.getScreenshort()
        submit_button.click()
        sleep(1)
        BlogDriver.getScreenshort()

        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("小ming")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        sleep(1)
        BlogDriver.getScreenshort()
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()

        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("小ming")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("1234567")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        sleep(1)
        BlogDriver.getScreenshort()










